package com.cebbank.sz.cebtemplate.utils;

import java.util.Map;

/**
 * @author sucz
 * @create 2020/1/8 14:11
 */
public class SoapXmlUtil {

    /**
     * 转换为<key>value</key>标签字符串
     * @param map
     * @return
     */
    public static String mapToTagStr(Map<String, Object> map) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            sb.append("<").append(entry.getKey()).append(">")
                .append(entry.getValue())
                .append("</").append(entry.getKey()).append(">");
        }
        return sb.toString();
    }

    /**
     * 获取soapXml字符串
     * @param str1
     * @param str2
     * @return
     */
    public static String getSoapXmlStr(String str1, String str2) {
        return "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
                "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org\">" +
                    "<soapenv:Header/>" +
                    "<soapenv:Body>" +
                        "<tem:HIPMessageServer>" +
                            "<tem:input1>" +
                                str1 +
                            "</tem:input1>" +
                            "<tem:input2>" +
                                "<![CDATA[<Request>" + str2 + "</Request>]]>" +
                            "</tem:input2>" +
                        "</tem:HIPMessageServer>" +
                    "</soapenv:Body>" +
                "</soapenv:Envelope>";
    }

}
